﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography.X509Certificates;
namespace TestReatXML
{
    public class SettingsValidator
    {
        internal const String date_format = "yyyy-MM-dd HHmmss";
        internal static void validateAndSave(Properties.Settings settings)
        {

            try
            {
                validate(settings);
                settings.Save();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        internal static void validate(Properties.Settings settings)
        {
            try
            {
                validateCertificate(settings.certificate_path, settings.pwd);
                validateConnectionString(settings.db_connection, settings.autoincrement_retrive);
                if (settings.url == String.Empty || settings.url.Trim() == String.Empty)
                    throw new Exception("Specify url!!!");
                if (!(System.IO.Directory.Exists(settings.xml_output)))
                {
                    if (System.IO.Directory.Exists(settings.xml_output))
                        throw new Exception(settings.xml_output == String.Empty ? "Specify xml output" : ("Path '" + settings.xml_output + "' doesn't exists!!!"));

                   
                }
                settings.Save();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        internal static void validateCertificate(String file, String pwd)
        {
            X509Certificate Cert = new X509Certificate2(file, pwd);
        }


        internal static void validateConnectionString(String connString, String identity)
        {
            DBOperation.validateConnectionString(connString, identity);
        }
    }
}

